<!DOCTYPE HTML>
<html lang="en" >
    
    <head>
        
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <title>原型链 | JavaScript 高级</title>
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <meta name="description" content="">
        <meta name="generator" content="GitBook 2.2.0">
        
        
        <meta name="HandheldFriendly" content="true"/>
        <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
        <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">
        
    <link rel="stylesheet" href="../gitbook/style.css">
    
    

        
    
    
    <link rel="next" href="../e2bb52a93f2a04d3848c6bc059d4442d/b8c198488b5b2ca72efdae292161824f.html" />
    
    
    <link rel="prev" href="../e2bb52a93f2a04d3848c6bc059d4442d/index.html" />
    

        
    </head>
    <body>
        
        
    <div class="book" data-level="2.1" data-basepath=".." data-revision="Tue Mar 01 2016 06:46:18 GMT+0800 (CST)">
    

<div class="book-summary">
    <div class="book-search">
        <input type="text" placeholder="Type to search" class="form-control" />
    </div>
    <ul class="summary">
        
        
        
        

        

        
    
        <li class="chapter " data-level="0" data-path="index.html">
            
                
                    <a href="../index.html">
                
                        <i class="fa fa-check"></i>
                        
                        JavaScript 高级
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1" data-path="e9c9c586570ff813bf127694b025d155/index.html">
            
                
                    <a href="../e9c9c586570ff813bf127694b025d155/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.</b>
                        
                        面向对象进阶
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.1" data-path="e9c9c586570ff813bf127694b025d155/c46418c7328d2a8b05cd6ccedd603f88.html">
            
                
                    <a href="../e9c9c586570ff813bf127694b025d155/c46418c7328d2a8b05cd6ccedd603f88.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.1.</b>
                        
                        面向对象基础复习
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="e9c9c586570ff813bf127694b025d155/40a6014bee4d6724e7aa800253818de5.html">
            
                
                    <a href="../e9c9c586570ff813bf127694b025d155/40a6014bee4d6724e7aa800253818de5.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.2.</b>
                        
                        原型的基本概念
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="e9c9c586570ff813bf127694b025d155/f93b5f4ffff4f7cc386af737772af5d5.html">
            
                
                    <a href="../e9c9c586570ff813bf127694b025d155/f93b5f4ffff4f7cc386af737772af5d5.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.3.</b>
                        
                        继承的概念
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="e9c9c586570ff813bf127694b025d155/9c3f525ec8bdda16f7618bcb3c936b98.html">
            
                
                    <a href="../e9c9c586570ff813bf127694b025d155/9c3f525ec8bdda16f7618bcb3c936b98.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.4.</b>
                        
                        Object 对象
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="e9c9c586570ff813bf127694b025d155/3c5d0a2365c2b15c5839ac6e1de9f9ea.html">
            
                
                    <a href="../e9c9c586570ff813bf127694b025d155/3c5d0a2365c2b15c5839ac6e1de9f9ea.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.5.</b>
                        
                        Function 对象
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="e9c9c586570ff813bf127694b025d155/3db73eb5d8866141920eb0d067ba68c3.html">
            
                
                    <a href="../e9c9c586570ff813bf127694b025d155/3db73eb5d8866141920eb0d067ba68c3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.6.</b>
                        
                        作用域链
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="e9c9c586570ff813bf127694b025d155/7c0fb98a684b27a818b1b546418cb62c.html">
            
                
                    <a href="../e9c9c586570ff813bf127694b025d155/7c0fb98a684b27a818b1b546418cb62c.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.7.</b>
                        
                        闭包的基本概念
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="e9c9c586570ff813bf127694b025d155/bec81e72f2f0c7d6d17bd137036d3286.html">
            
                
                    <a href="../e9c9c586570ff813bf127694b025d155/bec81e72f2f0c7d6d17bd137036d3286.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.8.</b>
                        
                        getter 与 setter
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2" data-path="e2bb52a93f2a04d3848c6bc059d4442d/index.html">
            
                
                    <a href="../e2bb52a93f2a04d3848c6bc059d4442d/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.</b>
                        
                        面向对象高级
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter active" data-level="2.1" data-path="e2bb52a93f2a04d3848c6bc059d4442d/5d3938919f20993f4b502f77cb59536f.html">
            
                
                    <a href="../e2bb52a93f2a04d3848c6bc059d4442d/5d3938919f20993f4b502f77cb59536f.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.1.</b>
                        
                        原型链
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.2" data-path="e2bb52a93f2a04d3848c6bc059d4442d/b8c198488b5b2ca72efdae292161824f.html">
            
                
                    <a href="../e2bb52a93f2a04d3848c6bc059d4442d/b8c198488b5b2ca72efdae292161824f.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.2.</b>
                        
                        函数的四中调用模式
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.3" data-path="e2bb52a93f2a04d3848c6bc059d4442d/0f37e1ef8250b257649a6d584bd33fb6.html">
            
                
                    <a href="../e2bb52a93f2a04d3848c6bc059d4442d/0f37e1ef8250b257649a6d584bd33fb6.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.3.</b>
                        
                        对象的创建模式
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.4" data-path="e2bb52a93f2a04d3848c6bc059d4442d/4fa341af02385d07831cfb4509d5bd20.html">
            
                
                    <a href="../e2bb52a93f2a04d3848c6bc059d4442d/4fa341af02385d07831cfb4509d5bd20.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.4.</b>
                        
                        继承的方式
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.5" data-path="e2bb52a93f2a04d3848c6bc059d4442d/a8d890e0bae896874f9af984daf86a53.html">
            
                
                    <a href="../e2bb52a93f2a04d3848c6bc059d4442d/a8d890e0bae896874f9af984daf86a53.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.5.</b>
                        
                        闭包案例
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.6" data-path="e2bb52a93f2a04d3848c6bc059d4442d/6cc37fe6e9df40a64594e3417c638703.html">
            
                
                    <a href="../e2bb52a93f2a04d3848c6bc059d4442d/6cc37fe6e9df40a64594e3417c638703.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.6.</b>
                        
                        正则表达式对象
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.7" data-path="e2bb52a93f2a04d3848c6bc059d4442d/0e3ef80c8612c6c6eb5baa8f397b9494.html">
            
                
                    <a href="../e2bb52a93f2a04d3848c6bc059d4442d/0e3ef80c8612c6c6eb5baa8f397b9494.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.7.</b>
                        
                        XMLHttpRequest 对象
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    


        
        <li class="divider"></li>
        <li>
            <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
                Published with GitBook
            </a>
        </li>
        
    </ul>
</div>

    <div class="book-body">
        <div class="body-inner">
            <div class="book-header">
    <!-- Actions Left -->
    <a href="#" class="btn pull-left toggle-summary" aria-label="Table of Contents"><i class="fa fa-align-justify"></i></a>
    <a href="#" class="btn pull-left toggle-search" aria-label="Search"><i class="fa fa-search"></i></a>
    
    <div id="font-settings-wrapper" class="dropdown pull-left">
        <a href="#" class="btn toggle-dropdown" aria-label="Font Settings"><i class="fa fa-font"></i>
        </a>
        <div class="dropdown-menu font-settings">
    <div class="dropdown-caret">
        <span class="caret-outer"></span>
        <span class="caret-inner"></span>
    </div>

    <div class="buttons">
        <button type="button" id="reduce-font-size" class="button size-2">A</button>
        <button type="button" id="enlarge-font-size" class="button size-2">A</button>
    </div>

    <div class="buttons font-family-list">
        <button type="button" data-font="0" class="button">Serif</button>
        <button type="button" data-font="1" class="button">Sans</button>
    </div>

    <div class="buttons color-theme-list">
        <button type="button" id="color-theme-preview-0" class="button size-3" data-theme="0">White</button>
        <button type="button" id="color-theme-preview-1" class="button size-3" data-theme="1">Sepia</button>
        <button type="button" id="color-theme-preview-2" class="button size-3" data-theme="2">Night</button>
    </div>
</div>

    </div>

    <!-- Actions Right -->
    
    <div class="dropdown pull-right">
        <a href="#" class="btn toggle-dropdown" aria-label="Share"><i class="fa fa-share-alt"></i>
        </a>
        <div class="dropdown-menu font-settings dropdown-left">
            <div class="dropdown-caret">
                <span class="caret-outer"></span>
                <span class="caret-inner"></span>
            </div>
            <div class="buttons">
                <button type="button" data-sharing="twitter" class="button">
                    Share on Twitter
                </button>
                <button type="button" data-sharing="google-plus" class="button">
                    Share on Google
                </button>
                <button type="button" data-sharing="facebook" class="button">
                    Share on Facebook
                </button>
                <button type="button" data-sharing="weibo" class="button">
                    Share on Weibo
                </button>
                <button type="button" data-sharing="instapaper" class="button">
                    Share on Instapaper
                </button>
            </div>
        </div>
    </div>
    

    
    <a href="#" target="_blank" class="btn pull-right google-plus-sharing-link sharing-link" data-sharing="google-plus" aria-label="Google"><i class="fa fa-google-plus"></i></a>
    
    
    <a href="#" target="_blank" class="btn pull-right facebook-sharing-link sharing-link" data-sharing="facebook" aria-label="Facebook"><i class="fa fa-facebook"></i></a>
    
    
    <a href="#" target="_blank" class="btn pull-right twitter-sharing-link sharing-link" data-sharing="twitter" aria-label="Twitter"><i class="fa fa-twitter"></i></a>
    
    
    


    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../" >JavaScript 高级</a>
    </h1>
</div>

            <div class="page-wrapper" tabindex="-1">
                <div class="page-inner">
                
                
                    <section class="normal" id="section-">
                    
                        <h1 id="%E5%8E%9F%E5%9E%8B%E9%93%BE">&#x539F;&#x578B;&#x94FE;</h1>
<p>&#x4E3B;&#x8981;&#x5185;&#x5BB9;:</p>
<ul>
<li>&#x5BF9;&#x8C61;&#x90FD;&#x6709;&#x539F;&#x578B;</li>
<li>Object &#x5BF9;&#x8C61;&#x7684;&#x539F;&#x578B;</li>
<li>&#x51FD;&#x6570;&#x5BF9;&#x8C61;&#x7684;&#x539F;&#x578B;</li>
<li>&#x539F;&#x578B;&#x94FE;</li>
<li>&#x5C5E;&#x6027;&#x641C;&#x7D22;&#x539F;&#x5219;</li>
</ul>
<p>&#x524D;&#x9762;&#x5DF2;&#x7ECF;&#x4ECB;&#x7ECD;&#x8FC7;&#x539F;&#x578B;&#x4E0E;&#x4E00;&#x822C;&#x5BF9;&#x8C61;&#x7684;&#x5173;&#x7CFB;, &#x51FD;&#x6570;&#x4E0E; <code>Function</code> &#x7B49;&#x7684;&#x5173;&#x7CFB;&#x4E86;. &#x53EF;&#x4EE5;&#x53D1;&#x73B0;&#x4E00;&#x822C;&#x7684;&#x5BF9;&#x8C61;, &#x6784;&#x9020;&#x51FD;&#x6570;, <code>Function</code>, &#x548C; <code>Object</code> &#x7B49;&#x90FD;&#x662F;&#x6709;&#x4E00;&#x5B9A;&#x5185;&#x5728;&#x8054;&#x7CFB;&#x7684;. &#x63A5;&#x4E0B;&#x6765;&#x6211;&#x4EEC;&#x8BE6;&#x7EC6;&#x8BA8;&#x8BBA;&#x5B83;&#x4EEC;&#x4E4B;&#x95F4;&#x7684;&#x8054;&#x7CFB;, &#x7ED9;&#x51FA;&#x4E00;&#x4E2A;&#x5B8C;&#x6574;&#x7684;&#x63CF;&#x8FF0;.</p>
<p><span style="color: red; font-weight: bolder;">&#x6CE8;&#x610F;, &#x672C;&#x8282;&#x5185;&#x5BB9;&#x4F1A;&#x6BD4;&#x8F83;&#x7ED5;. &#x4F46;&#x662F;&#x975E;&#x5E38;&#x91CD;&#x8981;.</span></p>
<h2 id="%E5%A4%8D%E4%B9%A0%E5%89%8D%E9%9D%A2%E7%9A%84%E5%86%85%E5%AE%B9">&#x590D;&#x4E60;&#x524D;&#x9762;&#x7684;&#x5185;&#x5BB9;</h2>
<p>&#x524D;&#x9762;&#x4ECB;&#x7ECD;&#x7684;&#x5185;&#x5BB9;&#x7B80;&#x5355;&#x6765;&#x8BF4;&#x5C31;&#x662F;:</p>
<ul>
<li>&#x81EA;&#x5B9A;&#x4E49;&#x5BF9;&#x8C61;&#x7EE7;&#x627F;&#x81EA;&#x6784;&#x9020;&#x51FD;&#x6570;&#x7684;&#x539F;&#x578B;</li>
<li>&#x6784;&#x9020;&#x51FD;&#x6570;&#x7EE7;&#x627F;&#x81EA; <code>Function.prototype</code></li>
<li><code>Function.prototype</code> &#x4F5C;&#x4E3A;&#x5BF9;&#x8C61;&#x7EE7;&#x627F;&#x81EA; <code>Object.prototype</code></li>
<li><code>Function</code> &#x548C; <code>Object</code> &#x4F5C;&#x4E3A;&#x51FD;&#x6570;&#x7EE7;&#x627F;&#x81EA; <code>Function.prototype</code></li>
</ul>
<p>&#x63A5;&#x4E0B;&#x6765;&#x6211;&#x4EEC;&#x5C06;&#x5176;&#x5C40;&#x90E8;&#x7684;&#x903B;&#x8F91;&#x8FDB;&#x884C;&#x5C55;&#x5F00;.</p>
<h3 id="%E8%87%AA%E5%AE%9A%E4%B9%89%E5%AF%B9%E8%B1%A1%E7%BB%A7%E6%89%BF%E8%87%AA%E6%9E%84%E9%80%A0%E5%87%BD%E6%95%B0%E7%9A%84%E5%8E%9F%E5%9E%8B">&#x81EA;&#x5B9A;&#x4E49;&#x5BF9;&#x8C61;&#x7EE7;&#x627F;&#x81EA;&#x6784;&#x9020;&#x51FD;&#x6570;&#x7684;&#x539F;&#x578B;</h3>
<p>&#x6839;&#x636E;&#x524D;&#x9762;&#x7684;&#x77E5;&#x8BC6;, &#x5206;&#x6790;&#x4E0B;&#x9762;&#x4EE3;&#x7801;:</p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Foo</span>(<span class="hljs-params"></span>) </span>{}
<span class="hljs-keyword">var</span> foo = <span class="hljs-keyword">new</span> Foo();
</code></pre>
<p>&#x7B80;&#x5355;&#x5206;&#x6790;&#x4E00;&#x4E0B;:</p>
<ul>
<li>&#x9996;&#x5148; <code>Foo</code> &#x662F;&#x6784;&#x9020;&#x51FD;&#x6570;. &#x90A3;&#x4E48;&#x5B58;&#x5728;&#x5BF9;&#x8C61; <code>Foo.prototype</code>.</li>
<li>&#x540C;&#x65F6; <code>Foo</code> &#x7EE7;&#x627F;&#x81EA; <code>Function.prototype</code>, &#x662F;&#x51FD;&#x6570; <code>Function</code> &#x7684;&#x5B9E;&#x4F8B;.</li>
<li>&#x7136;&#x540E;&#x5229;&#x7528; <code>Foo</code> &#x521B;&#x5EFA;&#x5BF9;&#x8C61; <code>foo</code>, <code>foo</code> &#x7EE7;&#x627F;&#x81EA; <code>Foo.prototype</code>.</li>
</ul>
<p>&#x5229;&#x7528;&#x56FE;&#x7ED8;&#x5236;&#x51FA;&#x903B;&#x8F91;:</p>
<p><img src="../images/Snip20160227_39.png" alt=""></p>
<h3 id="-object-%E7%9A%84%E5%AE%9E%E4%BE%8B%E7%BB%A7%E6%89%BF%E8%87%AA-object-prototype"><code>Object</code> &#x7684;&#x5B9E;&#x4F8B;&#x7EE7;&#x627F;&#x81EA; <code>Object.prototype</code></h3>
<p>&#x518D;&#x6765;&#x770B;&#x4E00;&#x4E2A;&#x7279;&#x6B8A;&#x7684;&#x6784;&#x9020;&#x51FD;&#x6570; <code>Object</code>. &#x5206;&#x6790;&#x7531;&#x5B83;&#x521B;&#x5EFA;&#x5904;&#x7406;&#x7684;&#x5BF9;&#x8C61;&#x7EE7;&#x627F;&#x7ED3;&#x6784;. &#x770B;&#x4E0B;&#x9762;&#x4EE3;&#x7801;:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> o = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Object</span>();
</code></pre>
<p>&#x7B80;&#x5355;&#x5206;&#x6790;&#x4E00;&#x4E0B;:</p>
<ul>
<li>&#x6784;&#x9020;&#x51FD;&#x6570; <code>Object</code> &#x662F; <code>Function</code> &#x7684;&#x5B9E;&#x4F8B;, &#x7EE7;&#x627F;&#x81EA; <code>Function.prototype</code>.</li>
<li>&#x5B9E;&#x4F8B; <code>o</code> &#x7EE7;&#x627F;&#x81EA; <code>Object.prototype</code>.</li>
</ul>
<p>&#x5229;&#x7528;&#x56FE;&#x7ED8;&#x5236;&#x51FA;&#x903B;&#x8F91;:</p>
<p><img src="../images/Snip20160227_41.png" alt=""></p>
<h3 id="%E5%8E%9F%E5%9E%8B%E7%BB%A7%E6%89%BF%E8%87%AA%E8%B0%81">&#x539F;&#x578B;&#x7EE7;&#x627F;&#x81EA;&#x8C01;?</h3>
<p>&#x53EF;&#x4EE5;&#x53D1;&#x73B0;&#x4E24;&#x6BB5;&#x7ED3;&#x6784;&#x903B;&#x8F91;&#x4F3C;&#x4E4E;&#x662F;&#x4E00;&#x6837;&#x7684;, &#x4F46;&#x662F;&#x4ED4;&#x7EC6;&#x89C2;&#x5BDF;, &#x5BF9;&#x8C61;&#x7684;&#x539F;&#x578B;&#x5BF9;&#x8C61;&#x5E76;&#x4E0D;&#x76F8;&#x540C;. &#x90A3;&#x4E48;&#x95EE;&#x9898;&#x662F;&#x539F;&#x578B;&#x4F5C;&#x4E3A;&#x4E00;&#x4E2A;&#x5BF9;&#x8C61;, &#x7EE7;&#x627F;&#x81EA;&#x8C01;&#x5462;?</p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Foo</span>(<span class="hljs-params"></span>) </span>{}
<span class="hljs-keyword">var</span> foo = <span class="hljs-keyword">new</span> Foo();
<span class="hljs-keyword">var</span> o = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Object</span>();
<span class="hljs-built_in">console</span>.log(Foo.prototype.__proto__);
<span class="hljs-built_in">console</span>.log(<span class="hljs-built_in">Object</span>.prototype.__proto__);
</code></pre>
<p>&#x6267;&#x884C;&#x7ED3;&#x679C;&#x4E3A;:</p>
<p><img src="../images/Snip20160227_43.png" alt=""></p>
<p>&#x53EF;&#x89C1; <code>Object.prototype</code> &#x4F5C;&#x4E3A;&#x5BF9;&#x8C61;, &#x5176; <code>__proto__</code> &#x4E3A; <code>null</code>. &#x610F;&#x5473;&#x7740;&#x627E;&#x4E0D;&#x5230;&#x5176;&#x539F;&#x578B;, &#x5B83;&#x5C31;&#x662F;&#x6700;&#x6839;&#x672C;&#x7684;&#x5BF9;&#x8C61;. &#x5BF9;&#x8C61; <code>foo</code> &#x7684;&#x539F;&#x578B;&#x5BF9;&#x8C61; <code>Foo.prototype</code> &#x5C31;&#x662F; <code>Object.prototype</code>.</p>
<pre><code class="lang-javascript"><span class="hljs-built_in">console</span>.log(Foo.prototype.__proto__ === <span class="hljs-built_in">Object</span>.prototype); <span class="hljs-comment">// =&gt; true</span>
</code></pre>
<p>&#x6574;&#x5408;&#x4E24;&#x5F20;&#x903B;&#x8F91;&#x7ED3;&#x6784;:</p>
<p><img src="../images/Snip20160227_44.png" alt=""></p>
<p>&#x6BD4;&#x8F83;&#x590D;&#x6742;, &#x4F46;&#x662F;&#x6162;&#x6162;&#x8FD8;&#x662F;&#x7406;&#x5F97;&#x6E05;&#x695A;. &#x63A5;&#x4E0B;&#x6765;&#x8FD8;&#x5269;&#x4E0B;&#x4E00;&#x4E2A;&#x95EE;&#x9898;, <code>Function.prototype</code> &#x4F5C;&#x4E3A;&#x5BF9;&#x8C61;, &#x5B83;&#x7684; <code>__proto__</code> &#x6307;&#x5411;&#x8C01;&#x5462;? &#x6253;&#x5370;&#x51FA;&#x6765;&#x67E5;&#x770B;:</p>
<p><img src="../images/Snip20160227_46.png" alt=""></p>
<p>&#x53EF;&#x89C1;, <code>Function.prototype</code> &#x7684;&#x539F;&#x578B;&#x5BF9;&#x8C61;&#x5C31;&#x662F; <code>Object.prototype</code>:</p>
<pre><code class="lang-javascript"><span class="hljs-built_in">console</span>.log(<span class="hljs-built_in">Function</span>.prototype.__proto__ === <span class="hljs-built_in">Object</span>.prototype); <span class="hljs-comment">// =&gt; true</span>
</code></pre>
<p>&#x6574;&#x7406;&#x4E00;&#x4E0B;&#x524D;&#x9762;&#x7684;&#x56FE;&#x7247;, &#x53EF;&#x4EE5;&#x5F97;&#x5230;:</p>
<p><img src="../images/Snip20160227_47.png" alt=""></p>
<p>&#x6839;&#x636E;&#x524D;&#x9762;&#x7684;&#x4E00;&#x6B65;&#x4E00;&#x6B65;&#x5206;&#x6790;, &#x53EF;&#x4EE5;&#x53D1;&#x73B0;&#x5728; JavaScript &#x4E2D;&#x6240;&#x6709;&#x7684;&#x6570;&#x636E;&#x4E4B;&#x95F4;&#x90FD;&#x6709;&#x8054;&#x7CFB;, &#x662F;&#x4E00;&#x4E2A;&#x6765;&#x6E90;&#x4E8E; <code>Object.prototype</code> &#x7684;&#x6811;&#x7ED3;&#x6784;.</p>
<h2 id="%E5%8E%9F%E5%9E%8B%E9%93%BE">&#x539F;&#x578B;&#x94FE;</h2>
<p>&#x7531;&#x524D;&#x9762;&#x7684;&#x5206;&#x6790;, &#x53EF;&#x4EE5;&#x53D1;&#x73B0;&#x5728; JavaScript &#x4E2D;, &#x4EFB;&#x4F55;&#x4E00;&#x4E2A;&#x6570;&#x636E;&#x90FD;&#x6765;&#x6E90;&#x4E8E; <code>Object.prototype</code>. &#x56E0;&#x6B64;&#x4EFB;&#x4F55;&#x4E00;&#x4E2A;&#x5BF9;&#x8C61;&#x5230; <code>Object.prototype</code> &#x90FD;&#x53EF;&#x4EE5;&#x627E;&#x5230;&#x4E00;&#x6761;&#x7EBF;&#x7D22;. &#x6211;&#x4EEC;&#x79F0;&#x8FD9;&#x6761;&#x7EBF;&#x7D22;&#x5C31;&#x662F;&#x539F;&#x578B;&#x94FE;. &#x5C06;&#x524D;&#x9762;&#x7684;&#x56FE;&#x518D;&#x8C03;&#x6574;&#x4E00;&#x4E0B;&#x4F4D;&#x7F6E;:</p>
<p><img src="../images/Snip20160227_49.png" alt=""></p>
<p>&#x90A3;&#x4E48;&#x8BBF;&#x95EE;&#x5BF9;&#x8C61;&#x6570;&#x636E;&#x7684;&#x65F6;&#x5019;&#x5C31;&#x4F1A;&#x5BF9;&#x539F;&#x578B;&#x94FE;&#x8FDB;&#x884C;&#x641C;&#x7D22;.</p>
<h2 id="%E5%B1%9E%E6%80%A7%E6%90%9C%E7%B4%A2%E5%8E%9F%E5%88%99">&#x5C5E;&#x6027;&#x641C;&#x7D22;&#x539F;&#x5219;</h2>
<p>&#x63A5;&#x4E0B;&#x6765;&#x6211;&#x4EEC;&#x6765;&#x770B;&#x5C5E;&#x6027;&#x641C;&#x7D22;&#x539F;&#x5219;. &#x5148;&#x6765;&#x770B;&#x8FD9;&#x4E00;&#x6BB5;&#x4EE3;&#x7801;:</p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Foo</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-keyword">this</span>.num = <span class="hljs-number">123</span>;
}
Foo.prototype.num = <span class="hljs-number">456</span>;
<span class="hljs-keyword">var</span> foo = <span class="hljs-keyword">new</span> Foo();
<span class="hljs-built_in">console</span>.log(foo.num);
</code></pre>
<p>&#x8FD9;&#x4E00;&#x6BB5;&#x4EE3;&#x7801;&#x6267;&#x884C;&#x7ED3;&#x679C;&#x662F;&#x4EC0;&#x4E48;&#x5462;? &#x8981;&#x89E3;&#x51B3;&#x8FD9;&#x4E2A;&#x95EE;&#x9898;, &#x6211;&#x4EEC;&#x9700;&#x8981;&#x77E5;&#x9053;&#x5C5E;&#x6027;&#x662F;&#x600E;&#x4E48;&#x8BBF;&#x95EE;&#x7684;.</p>
<p>&#x5728; JavaScript &#x4E2D;, &#x5982;&#x679C;&#x8BBF;&#x95EE;&#x5BF9;&#x8C61;&#x7684;&#x5C5E;&#x6027;, &#x9996;&#x5148;&#x4F1A;&#x68C0;&#x7D22;&#x5F53;&#x524D;&#x5BF9;&#x8C61;&#x4E2D;&#x662F;&#x5426;&#x5B58;&#x5728;&#x5C5E;&#x6027;, &#x5982;&#x679C;&#x5B58;&#x5728;&#x76F4;&#x63A5;&#x8C03;&#x7528;. &#x5982;&#x679C;&#x4E0D;&#x5B58;&#x5728;&#x5219;&#x4F1A;&#x5F80;&#x5176;&#x539F;&#x578B;&#x4E0A;&#x627E;, &#x5982;&#x679C;&#x539F;&#x578B;&#x4E2D;&#x4E5F;&#x6CA1;&#x6709;&#x8BE5;&#x5C5E;&#x6027;, &#x90A3;&#x4E48;&#x7EE7;&#x7EED;&#x5F80;&#x539F;&#x578B;&#x7684;&#x539F;&#x578B;&#x4E2D;&#x53BB;&#x627E;. &#x76F4;&#x5230;&#x627E;&#x5230;, &#x6216;&#x8005;&#x76F4;&#x5230;&#x5168;&#x5C40;&#x4F5C;&#x7528;&#x57DF;. &#x5982;&#x679C;&#x627E;&#x5230;, &#x76F4;&#x63A5;&#x83B7;&#x5F97;&#x8BE5;&#x7ED3;&#x679C;, &#x5982;&#x679C;&#x6CA1;&#x6709;&#x627E;&#x5230;&#x5219;&#x8FD4;&#x56DE; <code>undefined</code>.</p>
<p>&#x56E0;&#x6B64;&#x8FD9;&#x4E00;&#x6BB5;&#x4EE3;&#x7801;&#x7ED3;&#x679C;&#x662F; <code>123</code>.</p>
<p>&#x90A3;&#x4E48;&#x95EE;&#x9898;&#x6765;&#x4E86;. &#x6839;&#x636E;&#x539F;&#x578B;&#x7EE7;&#x627F;&#x7684;&#x539F;&#x5219;, &#x5982;&#x679C;&#x539F;&#x578B;&#x4E2D;&#x7684;&#x6570;&#x636E;&#x88AB;&#x4E00;&#x4E2A;&#x5BF9;&#x8C61;&#x4FEE;&#x6539;&#x4E86;, &#x90A3;&#x4E48;&#x53E6;&#x4E00;&#x4E2A;&#x5BF9;&#x8C61;&#x4F1A;&#x5F97;&#x5230;&#x591A;&#x5C11;&#x5462;?</p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Foo</span>(<span class="hljs-params"></span>) </span>{}
Foo.prototype.num = <span class="hljs-number">456</span>;
<span class="hljs-keyword">var</span> foo1 = <span class="hljs-keyword">new</span> Foo();
<span class="hljs-keyword">var</span> foo2 = <span class="hljs-keyword">new</span> Foo();
<span class="hljs-built_in">console</span>.log(foo1.num);
<span class="hljs-built_in">console</span>.log(foo2.num);
foo1.num = <span class="hljs-number">123</span>;
<span class="hljs-built_in">console</span>.log(foo1.num);
<span class="hljs-built_in">console</span>.log(foo2.num);
</code></pre>
<p>&#x8FD9;&#x91CC;&#x8FD0;&#x884C;&#x7684;&#x7ED3;&#x679C;&#x53C8;&#x662F;&#x591A;&#x5C11;&#x5462;? &#x4ECE;&#x539F;&#x578B;&#x7EE7;&#x627F;&#x7684;&#x89D2;&#x5EA6;&#x770B;, &#x539F;&#x578B;&#x4E2D;&#x7684;&#x6570;&#x636E;&#x5E94;&#x8BE5;&#x88AB; <code>foo1</code> &#x6240;&#x4FEE;&#x6539;, &#x56E0;&#x6B64;&#x7ED3;&#x679C;&#x5E94;&#x8BE5;&#x662F; 123, &#x4F46;&#x662F;&#x5E76;&#x975E;&#x5982;&#x6B64;. &#x6B64;&#x65F6;&#x4FEE;&#x6539;&#x7684;&#x53EA;&#x6709; <code>foo1</code> &#x7684;&#x6570;&#x636E;, &#x539F;&#x578B;&#x4E2D;&#x7684;&#x6570;&#x636E;&#x5E76;&#x6CA1;&#x6709;&#x88AB;&#x4FEE;&#x6539;. &#x8FD9;&#x662F;&#x4E3A;&#x4EC0;&#x4E48;&#x5462;?</p>
<p>&#x5B9E;&#x9645;&#x4E0A;, &#x5728; JavaScript &#x4E2D;, &#x8BBF;&#x95EE;&#x5C5E;&#x6027;&#x7684;&#x65F6;&#x5019;&#x6709;&#x4E00;&#x4E2A;&#x539F;&#x5219;. &#x5982;&#x679C;&#x662F;&#x8BFB;&#x53D6;&#x6570;&#x636E;, &#x90A3;&#x4E48;&#x6309;&#x7167;&#x5C5E;&#x6027;&#x641C;&#x7D22;&#x539F;&#x5219;&#x5C31;&#x53EF;&#x4EE5;&#x83B7;&#x5F97;&#x6570;&#x636E;. &#x4F46;&#x662F;&#x5982;&#x679C;&#x662F;&#x4FEE;&#x6539;&#x6570;&#x636E;, &#x90A3;&#x4E48;&#x5C31;&#x4F1A;&#x5728;&#x5F53;&#x524D;&#x4F5C;&#x7528;&#x57DF;&#x4E0A;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x8BE5;&#x540D;&#x5B57;&#x7684;&#x5C5E;&#x6027;, &#x5E76;&#x5BF9;&#x5176;&#x8D4B;&#x503C;. &#x5E76;&#x975E;&#x53BB;&#x4FEE;&#x6539;&#x539F;&#x578B;&#x4E2D;&#x7684;&#x6570;&#x636E;.</p>
<p><img src="../images/Snip20160227_51.png" alt=""></p>
<h2 id="%E5%B0%8F%E7%BB%93">&#x5C0F;&#x7ED3;</h2>
<ul>
<li>&#x81EA;&#x5B9A;&#x4E49;&#x5BF9;&#x8C61;&#x7684;&#x539F;&#x578B;&#x903B;&#x8F91;</li>
<li>&#x51FD;&#x6570;&#x7684;&#x539F;&#x578B;&#x903B;&#x8F91;</li>
<li>&#x539F;&#x578B;&#x94FE;&#x7684;&#x57FA;&#x672C;&#x7ED3;&#x6784;</li>
<li>&#x5C5E;&#x6027;&#x641C;&#x7D22;&#x539F;&#x5219;</li>
</ul>

                    
                    </section>
                
                
                </div>
            </div>
        </div>

        
        <a href="../e2bb52a93f2a04d3848c6bc059d4442d/index.html" class="navigation navigation-prev " aria-label="Previous page: 面向对象高级"><i class="fa fa-angle-left"></i></a>
        
        
        <a href="../e2bb52a93f2a04d3848c6bc059d4442d/b8c198488b5b2ca72efdae292161824f.html" class="navigation navigation-next " aria-label="Next page: 函数的四中调用模式"><i class="fa fa-angle-right"></i></a>
        
    </div>
</div>

        
<script src="../gitbook/app.js"></script>

<script>
require(["gitbook"], function(gitbook) {
    var config = {"fontSettings":{"theme":null,"family":"sans","size":2}};
    gitbook.start(config);
});
</script>

        
    </body>
    
</html>
